<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;

class Delybid extends Command
{
    protected function configure(){
        $this->setName('Delybid')->setDescription('delete Ybid');
    }

    protected function execute(Input $input, Output $output){
        //设置不超时
        ini_set('default_socket_timeout', -1);

        //连接本地的Redis 服务
        $redis = new \Redis();
        $redis->connect('192.168.58.110', 6379);
        $redis->auth('ac1995');


        while (true){
        $cc = $redis->LRANGE('Delybid',0, 1000);
        /*print_r($cc);*/
        $content = $redis->brPop('Delybid', 5000);
        if ($content){
            $data = json_decode($content['1'], true);
            echo '取到了最大条码***'.$data['dh']."\n";
            $code = $data['dh'];
            Db::execute("DELETE FROM dbo.Ls_Camera WHERE code  = :code", ['code' => $code]);
            Db::execute("DELETE FROM dbo.Ls_CameraFileRelation WHERE code  = :code", ['code' => $code]);
            Db::execute("DELETE FROM dbo.Ls_MSpecInputFirst WHERE code = :code", ['code' => $code]);
            Db::execute("DELETE FROM dbo.Ls_MSpecInputFirstApplyItem WHERE code = :code", ['code' => $code]);
            Db::execute("DELETE FROM dbo.Ls_MSpecInputSecondApplyItem WHERE code = :code", ['code' => $code]);
            Db::execute("DELETE FROM dbo.f_k_ybxx WHERE ybid = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.f_k_jymd WHERE ybid = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.f_k_ybxx_picture WHERE ybid  = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.t_lis_sampletransPro WHERE ybid  = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.t_lis_samplereg WHERE ybid = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.S_SampleDetail WHERE s_barcode = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.t_lis_tasks WHERE ybid  = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM t_lis_sampletransPro WHERE ybid= :ybid", ['ybid' => $code]);

                 echo '删除了*'.$data['dh'].'*的数据'."\n";
            }else{
                 echo '当前队列没得数据';
            }
        }
    }
}